﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;
using Microsoft.ApplicationBlocks.Data;
namespace XBYTestManagement
{
    public partial class FrmSolution : KryptonForm
    {
        public FrmSolution()
        {
            InitializeComponent();
        }

        private void btnNew_Click(object sender, EventArgs e)
        {
            FrmCreateSolution frmCreate = new FrmCreateSolution(this);
            frmCreate.ShowDialog();
            GridBind();
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            if (dgv.SelectedRows.Count == 0)
                return;
            DataRowView dr = (DataRowView)dgv.SelectedRows[0].DataBoundItem;
            int id = (int)dr["SolutionID"];
            FrmSolutionSetting frmSetting = new FrmSolutionSetting(id);

            frmSetting.ShowDialog();
        }
        private void GridBind()
        {
            dgv.AutoGenerateColumns = false;

            dgv.Columns["SolutionName"].DataPropertyName = "SolutionName";
            dgv.Columns["ProductNumber"].DataPropertyName = "ProductNumber";
            dgv.Columns["ProductName"].DataPropertyName = "ProductName";
            string sql = "select solution.ID as SolutionID,solution.SolutionName as SolutionName,product.ID as ProductID ,product.Number as ProductNumber,product.ProductName as ProductName from solution left join product on solution.productID = product.ID";
            DataSet ds = OleDbHelper.ExecuteDataset(OleDbHelper.connectionString, CommandType.Text, sql);
            dgv.DataSource = ds.Tables[0].DefaultView;
        }

        private void FrmSolution_Load(object sender, EventArgs e)
        {
            GridBind();
        }
    }
}
